In a class called ArrayListPractice
Create an arraylist of integers and fill it with the values 6,2,7,3,12,1, 9, 9, 3, 5,
9
- Create a method removeNines that will remove every 9 from the list.
- Create a method called public void replaceWithRandom (int k)
that will find all instances of k and replace it with a random
number between 0 and k
- Create a method called makeEven that will make all even (either staying if even, or moving up one if odd) (so 6 would become 6, 7 would become 8, 9 would become 10)
- Create a method called public void addZeros (int k) that will
add k zeroes after every instance of k, so if k was 3, it would
add three elements 0,0,0 after k.
- For advanced create a method that will return as an arraylist, all numbers that repeat.
- For advanced create a method that will return the data as an array of ints
Starter code:
import java.util.ArrayList;
public class ArrayListPractice {
ArrayList<Integer> myList=new ArrayList<Integer>();
public ArrayListPractice()
{
//6,2,7,3,12,1, 9, 9, 3, 5, 9
myList.add(6);
myList.add(2);
myList.add(7);
myList.add(3);
myList.add(12);
myList.add(1);
myList.add(9);
myList.add(9);
myList.add(3);
myList.add(5);
myList.add(9);
}
public static void main (String[] args)
{
ArrayListPractice a=new ArrayListPractice();
}
}
|